package com.lmx.repoDomain.repository;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiFindAll;
import io.katharsis.repository.annotations.JsonApiResourceRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.CustomerService;
import com.lmx.repoDomain.tmodel.CustomerDayFoodPlan;

@JsonApiResourceRepository(CustomerDayFoodPlan.class)
@Component
public class CustomerDayFoodPlanRepository extends BaseRepository<CustomerDayFoodPlan> {
	
	@Autowired
	private CustomerService customerService;

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(CustomerDayFoodPlan.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	@JsonApiFindAll
	public Iterable<CustomerDayFoodPlan> findAll(final QueryParams requestParams) {
		List<CustomerDayFoodPlan> listData = new ArrayList<>();
		Map<String, String> map = CommonUtil.getKeyMapByFilter(requestParams);
		Integer queryStartDate = -1;
		Integer queryEndDate = -1;
		if (map.containsKey("queryStartDate")) {
			queryStartDate = Integer.parseInt(map.get("queryStartDate"));
		}
		if (map.containsKey("queryEndDate")) {
			queryEndDate = Integer.parseInt(map.get("queryEndDate"));
		}

		 listData = customerService.getCustomerFoodPlan(null, queryStartDate,queryEndDate);
		// 设置分页信息
		commonService.setPageInfo(listData, requestParams);
		// 按照时间排序
		// Collections.sort(listData);
		// 根据请求分页数据获取相应数据
		listData = commonService.getPageData(listData, requestParams);
		return listData;
	}

	// @Override
	// @JsonApiSave
	// public CustomerDayFoodPlan save(CustomerDayFoodPlan data) {
	// if (data.getId() == null) {// create
	// dslJpaService.create(data);
	// } else {// update
	// if (data.getDelStatus() == 1) {// 删除
	// dslJpaService.update(data);
	// } else {
	// dslJpaService.update(data);
	// }
	// }
	// return data;
	// }

}
